package soundwave.com.demo.adpater;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import soundwave.com.demo.test.Messagecontet_test;
import soundwave.com.demo.R;

/**
 * Created by xu on 2017/3/26.
 */

public class MessageList_adapert extends ArrayAdapter<Messagecontet_test> {
    private Context context;
    private int layoutid;
    private LayoutInflater inflater=null;
    public MessageList_adapert(@NonNull Context context, @LayoutRes int resource, ArrayList<Messagecontet_test> messagecontent) {
        super(context, resource,messagecontent);
        this.context=context;
        this.layoutid=resource;


    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view=convertView;
        if (view==null){
            inflater=LayoutInflater.from(context);
            view=inflater.inflate(layoutid,null);
        }
        Messagecontet_test messagecontet_test=getItem(position);
        ImageView newsimg= (ImageView) view.findViewById(R.id.newsimg);
        TextView newsname= (TextView) view.findViewById(R.id.newsname);
        TextView data= (TextView) view.findViewById(R.id.data);

        newsimg.setImageResource(messagecontet_test.getNewsimg());
        newsname.setText(messagecontet_test.getNewsname());
        data.setText(messagecontet_test.getData());
        return view;
    }
}
